﻿/* Only set closed if JS-enabled */
document.getElementsByTagName('html')[0].className = 'isJS';

function tog(dt) {

    var display, dd = dt;
    /* get dd */
    do { dd = dd.nextSibling } while (dd.tagName != 'DD');
    toOpen = !dd.style.display;
    dd.style.display = toOpen ? 'block' : ''
    dt.getElementsByTagName('span')[0].innerHTML = toOpen ? '-' : '+';

}
function checkLength(str, minlen, maxlen) {
    alert(str);
    if (str == null) return false;
    var l = str.length;
    var blen = 0;
    for (i = 0; i < l; i++) {
        if ((str.charCodeAt(i) & 0xff00) != 0) {
            blen++;
        }
        blen++;
    }
    if (blen > maxlen || blen < minlen) {
        return false;
    }
    return true;
}
function getCookie(cookieName) {
    if (document.cookie.length > 0) {
        begin = document.cookie.indexOf(cookieName + "=");

        if (begin != -1) {
            begin += cookieName.length + 1;
            end = document.cookie.indexOf(";", begin);
            if (end == -1) end = document.cookie.length;
            return unescape(document.cookie.substring(begin, end));
        }
    }
    return null;
}

//RadScheduler
function insertAppointment(sender, e) {
    var slot = sender.get_activeModel().getTimeSlotFromDomElement(e.get_domEvent().target);
    sender.showAdvancedInsertForm(slot.get_startTime());
}

function editAppointment(sender, e) {
    var apt = e.get_appointment();
    sender.editAppointmentWithConfirmation(apt);
}

function BigSizeRadWindow(oWnd) {
    //oWnd.set_width(document.body.clientWidth);
    //oWnd.set_height(document.body.clientHeight);
    // oWnd.setSize(screen.width, screen.height);
    //oWnd.autoSize(true);
    //oWnd.setSize(900, 500);
    //oWnd.maximize();
    var width = document.body.clientWidth - 50;
    oWnd.set_width(width);
    oWnd.set_height(530);
    oWnd.center();
    //oWnd.moveTo(10, screen.height - document.body.clientHeight);
    //oWnd.center();
    //oWnd.show();
    //oWnd.maximize();
    //oWnd.setSize(screen.width, screen.height);
    //oWnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Resize);
}
function setDefaultRadWindowSize(oWnd) {
    //oWnd.setSize(screen.width, screen.height);

    //oWnd.setSize(900, 500);
    var width = document.body.clientWidth - 50;
    oWnd.set_width(width);
    oWnd.set_height(530);
    //oWnd.autoSize(true);
    //oWnd.setSize(900, 500);
    //oWnd.maximize();

    oWnd.center();
}
function checkNumericKeyInfo($char, $mozChar) {
    if ($mozChar != null) { // Look for a Mozilla-compatible browser
        if (($mozChar >= 48 && $mozChar <= 57) || $mozChar == 0 || $mozChar == 8 || $mozChar == 13)
            return true;
        else
            return false;
    }
    else { // Must be an IE-compatible Browser
        if (($char >= 48 && $char <= 57) || $char == 0 || $char == 8 || $char == 13)
            return true;
        else
            return false;
    }
}
function checkDoubleKeyInfo($char, $mozChar) {
    if ($mozChar != null) { // Look for a Mozilla-compatible browser
        if (($mozChar >= 48 && $mozChar <= 57) || $mozChar == 0 || $mozChar == 8 || $mozChar == 13 || $mozChar == 46 || $mozChar == 44)
            return true;
        else
            return false;
    }
    else { // Must be an IE-compatible Browser
        if (($char >= 48 && $char <= 57) || $char == 0 || $char == 8 || $char == 13)
            return true;
        else
            return false;
    }
}
function ShowCompareForm(id, url, ver) {
    //var link_compare = "<%=link_compare %>";
    //var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();
    //grid.get_masterTableView().selectItem(rowControl, true);
    //alert(url + id + "&ver=" + ver);
    var oWnd = window.radopen(url + id + "&ver=" + ver, "RadWindow1");
    BigSizeRadWindow(oWnd);
    oWnd.center();
    return false;
}
function ShowCompareFormCM(id, url, ver) {
    //var link_compare = "<%=link_compare %>";
    //var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();
    //grid.get_masterTableView().selectItem(rowControl, true);
    //alert(url + id + "&ver=" + ver);
    var oWnd = window.radopen(url + id + "&ver=" + ver, "RadWindow1");
    BigSizeRadWindow(oWnd);
    oWnd.center();
    return false;
}

//Lay gia tri query string
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

var Url = {

    // public method for url encoding
    encode: function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode: function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode: function (string) {
        string = string.replace(/\r\n/g, "\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode: function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while (i < utftext.length) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

